package nowcoder.hw.hj23;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine();
        StringBuilder resBuilder = new StringBuilder();
        TreeMap<Integer, Set<Character>> cntCharMapping = new TreeMap<>();
        Map<Character, Integer> charCntMapping = new HashMap<>();
        if (line != null && !line.trim().isEmpty()) {
            for (int i = 0; i < line.length(); i++) {
                char c = line.charAt(i);
                //出现次数++
                Integer cnt = charCntMapping.getOrDefault(c, 0);
                charCntMapping.put(c, cnt + 1);
                if (cnt > 0) {
                    //从原来次数集合移除元素
                    Set<Character> characters = cntCharMapping.get(cnt);
                    characters.remove(c);
                    if (characters.isEmpty()) {
                        //如果集合为空，从次数集合中移除，方便后续直接取出最少次数的元素集合
                        //思考，如果不移除，后续通过判断来取快不快？
                        cntCharMapping.remove(cnt);
                    }
                }
                //添加到新次数集合
                Set<Character> set = cntCharMapping.get(cnt + 1);
                if (set == null) {
                    set = new HashSet<>();
                    cntCharMapping.put(cnt + 1, set);
                }
                set.add(c);
            }

            Set<Character> characters = cntCharMapping.firstEntry().getValue();
            for (int i = 0; i < line.length(); i++) {
                char c = line.charAt(i);
                if (!characters.contains(c)) {
                    resBuilder.append(c);
                }
            }
        }
        System.out.println(resBuilder.toString());

    }
}